package com.longge;

public class CountOfPairs {

    public int[] countOfPairs(int n, int x, int y) {

        if (x > y) {
            int temp = x;
            x = y;
            y = temp;
        }
        int[] count = new int[n];
        int[][] dp = new int[n + 1][n + 1];
        for (int i = 1; i <= n; i++) {
            for (int j = i + 1; j <= n; j++) {
                if (x >= i && y == j && x != y) {
                    dp[i][j] = dp[i][j - (y - x)] + 1;
                } else {
                    dp[i][j] = dp[i][j - 1] + 1;
                }
            }
        }

        for (int i = 1; i <= n; i++) {
            for (int j = i + 1; j <= n; j++) {
                if (x < i && y == j) {
                    dp[i][j] = Math.min(dp[i][j], dp[x][y] + (i - x));
                }

                if (x == i && y > j) {
                    dp[i][j] = Math.min(dp[i][j], dp[x][y] + (y - j));
                }
            }
        }

        for (int k = 0; k < count.length; k++) {
            for (int[] ints : dp) {
                for (int j = 0; j < dp.length; j++) {
                    if (ints[j] == k + 1) {
                        count[k] += 2;
                    }
                }
            }
        }


        return count;
    }

    public static void main(String[] args) {
        int[] ints = new CountOfPairs().countOfPairs(6, 1, 5);
        System.out.println(ints);
    }
}
